package com.ruoyi.project.system.vehicle.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.system.vehicle.domain.ZzVehicle;
import com.ruoyi.project.system.vehicle.service.IZzVehicleService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 【请填写功能名称】Controller
 * 
 * @author ruoyi
 * @date 2020-10-31
 * @date 2020-10-29
 */
@Controller
@RequestMapping("/system/vehicle")
public class ZzVehicleController extends BaseController
{
    private String prefix = "system/vehicle";

    @Autowired
    private IZzVehicleService zzVehicleService;

    @RequiresPermissions("system:vehicle:view")
    @GetMapping()
    public String vehicle()
    {
        return prefix + "/vehicle";
    }

    /**
     * 查询【请填写功能名称】列表
     */
    @RequiresPermissions("system:vehicle:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(ZzVehicle zzVehicle)
    {
        startPage();
        List<ZzVehicle> list = zzVehicleService.selectZzVehicleList(zzVehicle);
        return getDataTable(list);
    }

    /**
     * 导出【请填写功能名称】列表
     */
    @RequiresPermissions("system:vehicle:export")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(ZzVehicle zzVehicle)
    {
        List<ZzVehicle> list = zzVehicleService.selectZzVehicleList(zzVehicle);
        ExcelUtil<ZzVehicle> util = new ExcelUtil<ZzVehicle>(ZzVehicle.class);
        return util.exportExcel(list, "vehicle");
    }

    /**
     * 新增【请填写功能名称】
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存【请填写功能名称】
     */
    @RequiresPermissions("system:vehicle:add")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(ZzVehicle zzVehicle)
    {
        return toAjax(zzVehicleService.insertZzVehicle(zzVehicle));
    }

    /**
     * 修改【请填写功能名称】
     */
    @GetMapping("/edit/{vehicleId}")
    public String edit(@PathVariable("vehicleId") Integer vehicleId, ModelMap mmap)
    {
        ZzVehicle zzVehicle = zzVehicleService.selectZzVehicleById(vehicleId);
        mmap.put("zzVehicle", zzVehicle);
        return prefix + "/edit";
    }

    /**
     * 修改保存【请填写功能名称】
     */
    @RequiresPermissions("system:vehicle:edit")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(ZzVehicle zzVehicle)
    {
        return toAjax(zzVehicleService.updateZzVehicle(zzVehicle));
    }

    /**
     * 删除【请填写功能名称】
     */
    @RequiresPermissions("system:vehicle:remove")
    @Log(title = "【请填写功能名称】", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(zzVehicleService.deleteZzVehicleByIds(ids));
    }
}
